#include<bits/stdc++.h>
using namespace std;

const int N = 2e5 + 5;

int n, a[N], ans;
bool col[N];

int score(int i) {
    for (int j = i - 1; j > 0; j--) {
        if (col[i] == col[j] && a[i] == a[j]) {
            return a[i];
        }
    }
    return 0;
}

void dfs(int i) {
    if (i == n) {
        int ans0 = 0;
        for (int i = 1; i <= n; i++) {
            ans0 += score(i);
        }
        ans = max(ans, ans0);
        return;
    }
    dfs(i + 1);
    col[i] = true;
    dfs(i + 1);
    col[i] = false;
}

int main() {
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    int T;
    cin >> T;
    while (T--) {
        n = 0;
        ans = 0;
        memset(a, 0, sizeof(a));
        memset(col, 0, sizeof(col));
        cin >> n;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
        }
        dfs(1);
        cout << ans << endl;
    }
    return 0;
}
